﻿
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        //获取当前用户
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str != "-1") {
                        var token = str.split('_');
                        instance[0].AddUser = token[0];
                        instance[0].AddTime = new Date();
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
        $("#btnSelect").click(function (event) { //单击选择，选择应聘人 
            parent.document.getElementById("dialog6_h").innerHTML = "选择应聘人——招聘录取"; // 
            parent.document.getElementById("EditUIWindow6").src = "../Extend/YUIDataTableList.aspx?entity=V_hrSelectHireCandidate&isShonwBtn=N&functionid=A285C465-5304-4683-A0B6-392714E1DFA8";
            parent.ShowDialogWindow();
        });
        $("select").each(function () {
            var optionId = $(this).attr(id);
            $(this).find("option").each(function () {
                if ($(this).val() == "") {
                    $(this).remove();
                }
            });
        });
        var fun = getPar(decodeURI(location.href), "fun"); //是否是查看
        if (fun == "view") {
            var planName = getPar(decodeURI(location.href), "planName");
            var postName = getPar(decodeURI(location.href), "postName");
            var name = getPar(decodeURI(location.href), "name");
            var idCard = getPar(decodeURI(location.href), "idCard");
            var auditMan = getPar(decodeURI(location.href), "auditMan");
            var deptName = getPar(decodeURI(location.href), "postName");
            var post = getPar(decodeURI(location.href), "post");
            $("#PlanName").val(planName);
            $("#PostName").val(postName);
            $("#Name").val(name);
            $("#IdCard").val(idCard);
            $("#txtAuditMan").val(auditMan);
            $("#txtDeptID").val(deptName);
            $("#PostID").append("<option>" + post + "</option>");
            $("#PostID").attr("disabled", true);
            $("#btnAuditMan").attr("disabled", true);
            $("#btnDeptID").attr("disabled", true);
            $("#btnSelect").attr("disabled", true);
            $("#JoinDate").attr("disabled", true);
            $("#ProbationPeriod").attr("disabled", true);
            $("#Remark").attr("readonly", "readonly");
            var btn = parent.document.getElementById("yui-gen7-button");
            $(btn).hide();
        }
    });
}

var ValueChanged = function () { //部门发生变化后
    var deptId = $("#DeptID").val();
    if (deptId == "") {
        return;
    }
    getPostions(deptId); //获取该部门下所有岗位
    instance[0].DeptID = deptId; //部门ID
}

//获取部门下的岗位
function getPostions(deptID) {
    $("#PostID").find('option').remove();
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=DatPost&condition=DeptID='" + deptID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total == 0) {
            $("#tishixinxi").text("该部门无岗位信息，请先维护部门岗位信息！");
        }
        else {
            $("#tishixinxi").text("");
            for (var o in list.rows) {
                var v = list.rows[o].PostID;
                var t = list.rows[o].PostName;
                if (typeof (t) != "undefined") {
                    $("#PostID").append("<option value='" + v + "' title='" + t + "'>" + t + "</option>");
                }
            }
        }
    });
}

var fnCheckData = function () {
    if ($("#Name").val() == "") {
        return "应聘人姓名不能为空！";
    }
    if ($("#txtAuditMan").val() == "") {
        return "审批人不能为空！";
    }
    if ($("#AuditDate").val() == "") {
        return "审批通过日期不能为空！";
    }
    if ($("#txtDeptID").val() == "") {
        return "部门不能为空！";
    }
    if ($("#PostID").val() == "") {
        return "岗位不能为空！";
    }
    if ($("#JoinDate").val() == "") {
        return "入职日期不能为空！";
    }
    if ($("#ProbationPeriod").val() == "") {
        return "试用期限不能为空！";
    }
}